<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="jt.classic.system.user.IUser"%>
<%@ page import="jt.classic.system.ISystem"%>
<%@ page import="org.limp.mine.StringTool"%>
<%@ page import="org.limp.mine.DateTrimmer"%>
<%@ page import="jt.classic.system.wordbook.XWordbook"%>
<%@ page import="java.util.List"%>
<%
	String context = jt.classic.system.ISystem.getContextPath();

	IUser user = ISystem.getSessionUser(request);

	List list = (List) request.getAttribute("list");
	List noonlist = (List) request.getAttribute("noon");
	List mscalelist = (List) request.getAttribute("mscale");
	List hscalelist = (List) request.getAttribute("hscale");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>领导日程管理</title>
</head>
<jsp:include page="../head.jsp"></jsp:include>
<link rel="stylesheet" type="text/css" href="<%=context%>/system/group/css/groupmanage.css" ></link>
<script type="text/javascript" src="<%=context %>/system/group/js/groupcombo4jsp.js"></script>
<script type="text/javascript" src="<%=context %>/system/object/js/page4neu.js"></script>
<script type="text/javascript" src="<%=context %>/system/dataindex/js/ditree4jsp.js"></script>
<script type="text/javascript" src="<%=context %>/system/object/js/init4core.js"></script>
<script>

   function handleAll(){
     var ck = document.getElementsByName("ldid");
     for(var i=0;i<ck.length;i++){
        ck[i].checked = !ck[i].checked;
     }
   }
   
   var sel;
   
   function handleSelect(t){
     sel = t;
     if(t == "dw"){
       var url = context + "/system/tree.do?method=selectgrouptree&type=radio";
       dialog(url,true,"",300,350);
     }else if(t == "pt"){
       var url = context + "/system/tree.do?method=selectuseronly&type=checkbox";
       dialog(url,true,"",300,350);
     }else if(t == "fw"){
       var t = document.form1.fbid.value.split(",");
       var st = "";
       for(var i=0;i<t.length;i++){
          if(t[i] != ""){
             st += "g" + t[i] + ",";
          }
       }
       var url = context + "/system/tree.do?method=selectgrouptree&type=checkbox" + "&defaultnode=" + st;
       dialog(url,true,"",300,350);
     }
   }
   
   function responseResult(ids,names,types){
      if(sel == "dw"){
         //document.form1.zbdwid.value = ids.replace(/g/g,"");
         document.form1.zbdwname.value = names;
      }else if(sel == "pt"){
         //document.form1.ptryid.value = ids.replace(/g/g,"");
         document.form1.ptry.value = names;
      }else if(sel == "fw"){
         document.form1.fbid.value = ids.replace(/g/g,"");
         document.form1.fbname.value = names;
      }
      
      closeDialog();
   }
   
   function catchHS(but){
      if(but == "stime"){
         document.getElementById("sarea").style.display = "none";
      }else if(but == "etime"){
         document.getElementById("earea").style.display = "none";
      }
   }
   
   function releaseHS(but){
      if(but == "stime"){
         document.getElementById("sarea").style.display = "";
      }else if(but == "etime"){
         document.getElementById("earea").style.display = "";
      }
   }
   
   function handleNoon(thizz){
      if(thizz.name == "snoon" && thizz.value != ""){
         document.getElementById("shour").disabled = true;
         document.getElementById("sminute").disabled = true;
      }else if(thizz.name == "snoon" && thizz.value == ""){
         document.getElementById("shour").disabled = false;
         document.getElementById("sminute").disabled = false;
      }else if(thizz.name == "enoon" && thizz.value != ""){
         document.getElementById("ehour").disabled = true;
         document.getElementById("eminute").disabled = true;
      }else if(thizz.name == "enoon" && thizz.value == ""){
         document.getElementById("ehour").disabled = false;
         document.getElementById("eminute").disabled = false;
      }
   }
   
   function handleSubmit(){
      var rnt = false;
      var ck = document.getElementsByName("ldid");
      var countLD = "";
      var chld = "";
      var chldid = "";
      var tempids = "";
      
      for(var i=0;i<ck.length;i++){
	     if(ck[i].checked){
	        rnt = true;
	        break;
	     }
	  }        
      
      if(!rnt){
         alert("请选择与会领导");
      }else if(isblank(document.form1.stime) || isblank(document.form1.etime)){
         alert("请设置开始时间或结束时间");
      }else if(isblank(document.form1.zbdwname)){
         alert("请选择主办单位");
      }else if(isblank(document.form1.fbid)){
         alert("请设置发布范围");
      }else if(confirm("确定提交")){
          for(var i=0;i<ck.length;i++){
	          if(ck[i].checked){
	             createHidden("ldid_" + i,ck[i].value);
	             createHidden("ldname_" + i,ck[i].getAttribute("iname"));
	             createHidden("ldgroupid_" + i,ck[i].getAttribute("igroupid"));
	             chld += ck[i].getAttribute("iname") + ",";
	             chldid += ck[i].value + ",";
	             countLD += i + ",";
	             tempids += ck[i].value + ",";
	          }
          }
      
          var stime = parseDate(document.form1.stime.value);

	      if(document.form1.snoon.value == ""){
	         stime += document.form1.shour.value + "" + document.form1.sminute.value;
	      }else{
	         stime += document.form1.snoon.value;
	      }
	      
	      var etime = parseDate(document.form1.etime.value);

	      if(document.form1.enoon.value == ""){
	         etime += document.form1.ehour.value + "" + document.form1.eminute.value;
	      }else{
	         etime += document.form1.enoon.value;
	      }
	      
	      createHidden("sdate",stime);
	      createHidden("edate",etime);
	      
	      var fbids = document.form1.fbid.value.split(",");
	      var fbnames = document.form1.fbname.value.split(",");
	      
	      var countFB = "";
	      
	      for(var i=0;i<fbids.length;i++){ 
	          createHidden("fbid_" + i,fbids[i]);
	          createHidden("fbname_" + i,fbnames[i]);
	          createHidden("fbtype_" + i,"g");
	          countFB += i + ",";
	      }
	      
	      createHidden("countFB",countFB);
	      
	      createHidden("countLD",countLD);

	      createHidden("chld",chld.substring(0,chld.length-1));
	      createHidden("chldid",chldid.substring(0,chldid.length-1));
	      
	      document.form1.action = context + "/app/ldrc.do?method=save";
	      document.form1.submit();
      }
   }
</script>
<body>
<form name="form1" id="form1" method="post" action="">
<div style="margin-top:15px;margin-left:15px;" align="left"><input type="button" class="button0"
	value=" 提 交 " onclick="javascript:handleSubmit();"> <input
	type="reset" class="button0" value=" 重 置 "></div>
<fieldset id="lanmu" style="width:90%;margin-left:15px;">
<legend>新建领导日程</legend>
<table width="600" class="tab4edit" border="0" align="center">
	<tr>
		<td width="100" class="td1" valign="top">出席领导&nbsp;<a
			href="javascript:void(0);" onclick="javascript:handleAll();">全选</a></td>
		<td align="left">
		<%
				if (list != null && !list.isEmpty()) {
				int count = 0;
				boolean r = false;
				for (int i = 0; i < list.size(); i++) {
					List l = (List) list.get(i);
					for (int j = 0; j < l.size(); j++) {
				Object[] obj = (Object[]) l.get(j);
				IUser u = (IUser) obj[0];
				String gid = (String) obj[1];
				if (u.iflag() == 0) {
					if (count == 10) {
						//out.print("<br>");
						count = 0;
					}
		%> <span for="u<%=i+"_"+j%>"><%=u.iname()%><input
			type="checkbox" name="ldid" id="u<%=i+"_"+j%>" igroupid="<%=gid%>"
			iname="<%=u.iname()%>" value="<%=u.id()%>" /></span> <%
 		count++;
 		}
 			}
 		}
 	}
 %>
		</td>
	</tr>
	<tr>
		<td class="td1">时间安排</td>
		<td>
		<div>开始时间&nbsp;<input
			type="text" class="box3" readonly name="stime" style="width:100px;"
			onclick="javascript:HS_setDate(this);" /> <span id="sarea"
			style="display:;"><select name="snoon"
			onchange="javascript:handleNoon(this);">
			<option value=""></option>
			<%
					if (noonlist != null && !noonlist.isEmpty()) {
					for (int i = 0; i < noonlist.size(); i++) {
						XWordbook wb = (XWordbook) noonlist.get(i);
			%>
			<option value="<%=wb.getID()%>"><%=wb.getName()%></value> <%
 	}
 	}
 %>
			
		</select>
		<select id="shour" name="shour">
			<%
					if (hscalelist != null && !hscalelist.isEmpty()) {
					for (int i = 0; i < hscalelist.size(); i++) {
						XWordbook wb = (XWordbook) hscalelist.get(i);
			%>
			<option value="<%=wb.getID()%>"><%=wb.getName()%></value> <%
 	}
 	}
 %>
		</select>时 
		<select id="sminute" name="sminute">
			<%
					if (mscalelist != null && !mscalelist.isEmpty()) {
					for (int i = 0; i < mscalelist.size(); i++) {
						XWordbook wb = (XWordbook) mscalelist.get(i);
			%>
			<option value="<%=wb.getID()%>"><%=wb.getName()%></value> <%
 	}
 	}
 %>
			
		</select>分 </span></div>
		<div>结束时间&nbsp;<input
			type="text" readonly class="box3" name="etime" style="width:100px;"
			onclick="javascript:HS_setDate(this)" /> <span id="earea"
			style="display:"><select name="enoon"
			onchange="javascript:handleNoon(this);">
			<option value=""></option>
			<%
					if (noonlist != null && !noonlist.isEmpty()) {
					for (int i = 0; i < noonlist.size(); i++) {
						XWordbook wb = (XWordbook) noonlist.get(i);
			%>
			<option value="<%=wb.getID()%>"><%=wb.getName()%></value> <%
 	}
 	}
 %>
			
		</select> <select id="ehour" name="ehour">
			<%
					if (hscalelist != null && !hscalelist.isEmpty()) {
					for (int i = 0; i < hscalelist.size(); i++) {
						XWordbook wb = (XWordbook) hscalelist.get(i);
			%>
			<option value="<%=wb.getID()%>"><%=wb.getName()%></value> <%
 	}
 	}
 %>
			
		</select>时 <select id="eminute" name="eminute">
			<%
					if (mscalelist != null && !mscalelist.isEmpty()) {
					for (int i = 0; i < mscalelist.size(); i++) {
						XWordbook wb = (XWordbook) mscalelist.get(i);
			%>
			<option value="<%=wb.getID()%>"><%=wb.getName()%></value> <%
 	}
 	}
 %>
			
		</select>分 </span></div>
		</td>
	</tr>
	<tr>
		<td class="td1">主办单位</td>
		<td>
		<input type="hidden" name="zbdwid" id="zbdwid" value="" special="gu" select="group" iwidth="500" root="root" guname="zbdwname"/>
    	<input type="hidden" name="zbdwname" id="zbdwname" value=""/>
		</td>
	</tr>
	<tr>
		<td class="td1">活动地点</td>
		<td><input type="text" class="box3"
			name="hddd" /></td>
	</tr>
	<tr>
		<td class="td1">活动内容</td>
		<td><textarea name="hdnr" class="box3"
			style="height:50px;"></textarea></td>
	</tr>
	<tr>
		<td class="td1">陪同人员</td>
		<td>
		<input type="hidden" name="ptryid" id="ptryid" value="" special="gu" select="user" root="root" guname="ptry"/>
    	<input type="hidden" name="ptry" id="ptry" value=""/>
		</td>
	</tr>
	<tr>
		<td class="td1">说明</td>
		<td><textarea name="sm" class="box3"
			style="height:50px;"></textarea></td>
	</tr>
	<tr>
		<td class="td1">登记人</td>
		<td><%=user.iname()%> <input type="hidden" name="djrid"
			value="<%=user.id()%>" /> <input type="hidden" name="djrname"
			value="<%=user.iname()%>" /> <input type="hidden" name="djdate"
			value="<%=DateTrimmer.getYMDHMS()%>" /></td>
	</tr>
	<tr>
		<td class="td1">备注</td>
		<td><textarea class="box3" name="bz"></textarea></td>
	</tr>
	<tr>
		<td class="td1">发布范围</td>
		<td>
		<input type="hidden" name="fbid" id="fbid" value="" special="gu" select="group" root="root" guname="fbname"/>
    	<input type="hidden" name="fbname" id="fbname" value=""/>
		</td>
	</tr>
</table>

	</fieldset>
</form>
<script>
initExtComponents();
</script>
</body>
</html>
